<template>
  <div id="AppguidanceSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="状态" prop="status">
          <el-select v-model="formInline.status" clearable>
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="formInline.name"
            placeholder="请输入名称"
            clearable
          />
        </el-form-item>
        <el-form-item label="排序" prop="sort" class="sortSelect">
          <el-select v-model="formInline.sort" placeholder="请选择">
            <el-option
              v-for="(item, index) in orderWayList"
              :key="'item' + index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="操作人" prop="operatorId">
          <el-select v-model="formInline.operatorId" clearable filterable>
            <el-option
              v-for="(item, index) in personList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getCreateTime } from '@utils/pubFunction'
import { getDpNum } from '@/api/system/user'

export default {
  name: 'AppguidanceSearch',
  msg: 'APP引导-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          status: '', // 状态
          name: '', // 名称
          sort: '',
          operatorId: '' // 审核人
        }
      }
    }
  },
  data() {
    return {
      // 状态
      statusList: [{ dictLabel: '全部', dictValue: '' }],
      // 排序
      orderWayList: [],
      // 审核人
      personList: [{ nickname: '全部', dapengUserId: '' }]
    }
  },
  mounted() {
    this.getStatusList()
    this.getCheckUser()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    async getStatusList() {
      //状态
      let data = await sysNormalDisable('welcome_status', 'guidanType')
      this.statusList = this.statusList.concat(data)
      // 排序规则
      this.orderWayList = await sysNormalDisable('welcome_sort')
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.sort = this.orderWayList[0].dictValue
    },
    // 审核人
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.personList = this.personList.concat(response)
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    }
  }
}
</script>

<style lang="less">
#AppguidanceSearch {
  .sortSelect {
    .el-input {
      &.el-input--suffix {
        width: 130px !important;
      }
    }
  }
  .el-input.el-input--suffix {
    .el-input__inner {
      padding-right: 25px !important;
    }
  }
}
</style>
